<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>安装docker | 如是的学习博客</title><meta name="keywords" content="docker"><meta name="author" content="rushiy"><meta name="copyright" content="rushiy"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="yum在线安装：Linux系统自带了docker软件包，但该软件包版本较低，一般不使用系统自带的docker。 我们可以在虚拟机中使用yum repolist命令，同步系统自带的软件包，发现结果都是1.13.1版本的docker，如下： 12345678910111213141516171819202122232425# yum info docker  # 查看服务器上的docker信息Load">
<meta property="og:type" content="article">
<meta property="og:title" content="安装docker">
<meta property="og:url" content="https://rushiy.gitee.io/docker/%E5%AE%89%E8%A3%85docker/index.html">
<meta property="og:site_name" content="如是的学习博客">
<meta property="og:description" content="yum在线安装：Linux系统自带了docker软件包，但该软件包版本较低，一般不使用系统自带的docker。 我们可以在虚拟机中使用yum repolist命令，同步系统自带的软件包，发现结果都是1.13.1版本的docker，如下： 12345678910111213141516171819202122232425# yum info docker  # 查看服务器上的docker信息Load">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-09-22T04:49:33.000Z">
<meta property="article:author" content="rushiy">
<meta property="article:tag" content="docker">
<meta name="twitter:card" content="summary"><link rel="shortcut icon" href="/img/favicon.jpg"><link rel="canonical" href="https://rushiy.gitee.io/docker/%E5%AE%89%E8%A3%85docker/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '安装docker',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-11-19 01:18:40'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/favicon.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">3</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">如是的学习博客</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">安装docker</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-09-22T04:49:33.000Z" title="发表于 2022-09-22 12:49:33">2022-09-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-11-18T17:18:40.941Z" title="更新于 2022-11-19 01:18:40">2022-11-19</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="安装docker"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="yum在线安装："><a href="#yum在线安装：" class="headerlink" title="yum在线安装："></a>yum在线安装：</h2><p><code>Linux</code>系统自带了<code>docker</code>软件包，但该软件包版本较低，一般不使用系统自带的docker。</p>
<p>我们可以在虚拟机中使用<code>yum repolist</code>命令，同步系统自带的软件包，发现结果都是1.13.1版本的docker，如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum info docker  <span class="comment"># 查看服务器上的docker信息</span></span></span><br><span class="line">Loaded plugins: fastestmirror</span><br><span class="line">Loading mirror speeds from cached hostfile</span><br><span class="line"> * base: mirrors.aliyun.com</span><br><span class="line"> * extras: mirrors.aliyun.com</span><br><span class="line"> * updates: mirrors.aliyun.com</span><br><span class="line">Available Packages</span><br><span class="line">Name        : docker   # 软件包名称</span><br><span class="line">Arch        : x86_64   # 适用平台</span><br><span class="line">Epoch       : 2</span><br><span class="line">Version     : 1.13.1   # docker版本信息</span><br><span class="line">Release     : 162.git64e9980.el7.centos</span><br><span class="line">Size        : 18 M     # 软件包大小</span><br><span class="line">Repo        : extras/7/x86_64   # 软件包仓库</span><br><span class="line">Summary     : Automates deployment of containerized applications</span><br><span class="line">URL         : https://github.com/docker/docker   # 软件包的url地址</span><br><span class="line">License     : ASL 2.0</span><br><span class="line">Description : Docker is an open-source engine that automates the deployment of any</span><br><span class="line">描述信息     : application as a lightweight, portable, self-sufficient container that will</span><br><span class="line">            : run virtually anywhere.</span><br><span class="line">            : </span><br><span class="line">            : Docker containers can encapsulate any payload, and will run consistently on</span><br><span class="line">            : and between virtually any server. The same container that a developer builds</span><br><span class="line">            : and tests on a laptop will run at scale, in production*, on VMs, bare-metal</span><br><span class="line">            : servers, OpenStack clusters, public instances, or combinations of the above.</span><br></pre></td></tr></table></figure>

<p>在阿里云源提供的docker最新（截至2022年底）版本为<code>20.10.9</code>，如下图所示：</p>
<p><img src="/pic/docker-pic/image-20221022115145335.png" alt="image-20221022115145335"></p>
<h3 id="配置yum源"><a href="#配置yum源" class="headerlink" title="配置yum源"></a>配置yum源</h3><p>输入网址<a target="_blank" rel="noopener" href="https://mirrors.aliyun.com/%E8%BF%9B%E5%85%A5%E9%98%BF%E9%87%8C%E9%95%9C%E5%83%8F%E7%BD%91%E7%AB%99%EF%BC%8C%E9%80%89%E6%8B%A9docker-ce%E8%BF%9B%E5%85%A5%E5%AD%90%E9%A1%B5%E9%9D%A2(%E5%AD%90%E9%A1%B5%E9%9D%A2%E4%B8%AD%E6%9C%89Linux%E3%80%81mac%E3%80%81win%E4%B8%89%E4%B8%AA%E5%AD%90%E7%9B%AE%E5%BD%95)%EF%BC%8C%E9%80%89%E6%8B%A9%E5%AF%B9%E5%BA%94%E7%9A%84Linux%E5%AD%90%E7%9B%AE%E5%BD%95%E8%BF%9B%E5%85%A5Linux%E7%89%88%E6%9C%AC%E7%9A%84docker%E7%9B%AE%E5%BD%95%EF%BC%8C%E6%8E%A5%E4%B8%8B%E6%9D%A5%E9%80%89%E6%8B%A9%E7%B3%BB%E7%BB%9F%E7%89%88%E6%9C%AC(%E8%AF%A5%E9%A1%B5%E9%9D%A2%E6%98%BE%E7%A4%BA%E4%B8%BB%E8%A6%81%E7%9A%84Linux%E5%8F%91%E8%A1%8C%E7%89%88)%EF%BC%8C%E6%AD%A4%E5%A4%84%E6%A0%B9%E6%8D%AELinux%E7%B3%BB%E7%BB%9F%E7%89%88%E6%9C%AC%E8%BF%9B%E8%A1%8C%E9%80%89%E6%8B%A9%EF%BC%8C%E7%82%B9%E5%87%BB%E8%BF%9B%E5%85%A5centos%E5%AD%90%E7%9B%AE%E5%BD%95%EF%BC%8C%E5%A6%82%E4%B8%8B%E5%9B%BE%EF%BC%9A">https://mirrors.aliyun.com/进入阿里镜像网站，选择docker-ce进入子页面(子页面中有Linux、mac、win三个子目录)，选择对应的Linux子目录进入Linux版本的docker目录，接下来选择系统版本(该页面显示主要的Linux发行版)，此处根据Linux系统版本进行选择，点击进入centos子目录，如下图：</a></p>
<img src="/pic/docker-pic/image-20200715151930491.png" alt="image-20200715151930491" style="zoom:67%;" />

<p>我们可以直接配置并使用该仓库进行docker的安装，如下：<br>参考文档：<a target="_blank" rel="noopener" href="https://developer.aliyun.com/mirror/docker-ce">https://developer.aliyun.com/mirror/docker-ce</a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装前关闭firewalld和selinux</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum install -y yum-utils device-mapper-persistent-data lvm2  <span class="comment"># 安装必要的软件</span></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">添加docker仓库，添加完成后就是国内阿里源仓库了，如果下载了国外的docker镜像仓库，可将网址替换成国内源</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</span>  </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum clean all &amp;&amp; yum repolist</span></span><br><span class="line">repo id                     repo name                                        status</span><br><span class="line">base/7/x86_64               CentOS-7 - Base - mirrors.aliyun.com             10,070</span><br><span class="line">docker-ce-stable/x86_64     Docker CE Stable - x86_64                        79</span><br><span class="line">epel/x86_64                 Extra Packages for Enterprise Linux 7 - x86_64   13,376</span><br><span class="line">extras/7/x86_64             CentOS-7 - Extras - mirrors.aliyun.com           412</span><br><span class="line">updates/7/x86_64            CentOS-7 - Updates - mirrors.aliyun.com          890</span><br><span class="line">repolist: 24,827  </span><br></pre></td></tr></table></figure>

<p>较旧的<code>Docker</code>版本称为<code>docker</code>或<code>docker-engine</code>。如果已安装这些程序，请卸载它们以及相关的依赖项。在进行安装之前先卸载系统自带的docker。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">rpm -qi docker-ce   <span class="comment"># 查看docker是否已经安装，如果安装需卸载</span></span></span><br><span class="line">package docker-ce is not installed</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">rpm -qi docker</span></span><br><span class="line">package docker is not installed</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">如果显示已经安装了docker，需要使用下面的命令卸载docker，再安装新版本的docker</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine</span></span><br></pre></td></tr></table></figure>

<h3 id="安装docker"><a href="#安装docker" class="headerlink" title="安装docker"></a>安装docker</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum -y install docker-ce   <span class="comment"># 主要安装了如下的软件</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">也可以安装指定版本的docker，使用yum时指定版本即可</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看docker版本信息</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker version</span>  </span><br><span class="line">Client: Docker Engine - Community  # docker客户端信息</span><br><span class="line"> Version:           19.03.12</span><br><span class="line"> API version:       1.40</span><br><span class="line"> Go version:        go1.13.10</span><br><span class="line"> Git commit:        48a66213fe</span><br><span class="line"> Built:             Mon Jun 22 15:46:54 2020   # 安装时间</span><br><span class="line"> OS/Arch:           linux/amd64   # 系统类型</span><br><span class="line"> Experimental:      false</span><br><span class="line">Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">提示docker daemon未运行，运行后会显示docker daemon的信息</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">rpm -qi docker-ce  <span class="comment"># 查看安装的docker-ce信息</span></span></span><br><span class="line">Name        : docker-ce</span><br><span class="line">Epoch       : 3</span><br><span class="line">Version     : 19.03.12</span><br><span class="line">Release     : 3.el7</span><br><span class="line">Architecture: x86_64</span><br><span class="line">Install Date: Wed 15 Jul 2020 03:32:29 PM CST</span><br><span class="line">Group       : Tools/Docker</span><br><span class="line">Size        : 106714688</span><br><span class="line">License     : ASL 2.0</span><br><span class="line">Signature   : RSA/SHA512, Tue 23 Jun 2020 05:21:51 AM CST, Key ID c52feb6b621e9f35</span><br><span class="line">Source RPM  : docker-ce-19.03.12-3.el7.src.rpm</span><br><span class="line">Build Date  : Mon 22 Jun 2020 11:46:41 PM CST</span><br><span class="line">Build Host  : 7d52e4e2ee0b</span><br><span class="line">Relocations : (not relocatable)</span><br><span class="line">Packager    : Docker &lt;support@docker.com&gt;</span><br><span class="line">Vendor      : Docker   # vendor [ˈvendər]  小贩，这里指软件提供厂商</span><br><span class="line">URL         : https://www.docker.com   # 官方url地址</span><br><span class="line">Summary     : The open-source application container engine</span><br><span class="line">Description :  # 描述信息</span><br><span class="line">Docker is a product for you to build, ship and run any application as a</span><br><span class="line">lightweight container.</span><br><span class="line"></span><br><span class="line">Docker containers are both hardware-agnostic and platform-agnostic. This means</span><br><span class="line">they can run anywhere, from your laptop to the largest cloud compute instance and</span><br><span class="line">everything in between - and they don&#x27;t require you to use a particular</span><br><span class="line">language, framework or packaging system. That makes them great building blocks</span><br><span class="line">for deploying and scaling web apps, databases, and backend services without</span><br><span class="line">depending on a particular stack or provider.</span><br></pre></td></tr></table></figure>

<p> 到此，dockers就安装完成了。</p>
<h3 id="配置镜像加速"><a href="#配置镜像加速" class="headerlink" title="配置镜像加速"></a>配置镜像加速</h3><p>给docker镜像加速，我们在创建容器的时候，是需要到官网上下载指定版本的软件的，因此下载镜像的快慢是我们必须关注的话题，一般可以使用官网的<code>docker cn</code>、<code>阿里云加速器</code>、<code>中国科技大学加速器</code>、<code>163加速器</code>等。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /etc/docker</span></span><br><span class="line">ls: cannot access /etc/docker: No such file or directory</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">mkdir</span> /etc/docker</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim /etc/docker/daemon.json <span class="comment"># 镜像加速，自建该文件</span></span></span><br><span class="line">&#123;</span><br><span class="line">    &quot;registry-mirrors&quot;: [&quot;https://registry.docker-cn.com&quot;,&quot;http://hub-mirror.c.163.com&quot;]</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动docker</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl start docker  &amp;&amp; systemctl <span class="built_in">enable</span> docker</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker version</span></span><br><span class="line">Client: Docker Engine - Community   # docker客户端信息</span><br><span class="line"> Version:           19.03.12</span><br><span class="line"> API version:       1.40</span><br><span class="line"> Go version:        go1.13.10</span><br><span class="line"> Git commit:        48a66213fe</span><br><span class="line"> Built:             Mon Jun 22 15:46:54 2020</span><br><span class="line"> OS/Arch:           linux/amd64</span><br><span class="line"> Experimental:      false</span><br><span class="line"></span><br><span class="line">Server: Docker Engine - Community   # docker服务端信息</span><br><span class="line"> Engine:</span><br><span class="line">  Version:          19.03.12</span><br><span class="line">  API version:      1.40 (minimum version 1.12)</span><br><span class="line">  Go version:       go1.13.10</span><br><span class="line">  Git commit:       48a66213fe</span><br><span class="line">  Built:            Mon Jun 22 15:45:28 2020</span><br><span class="line">  OS/Arch:          linux/amd64</span><br><span class="line">  Experimental:     false</span><br><span class="line"> containerd:</span><br><span class="line">  Version:          1.2.13</span><br><span class="line">  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429</span><br><span class="line"> runc:</span><br><span class="line">  Version:          1.0.0-rc10</span><br><span class="line">  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd</span><br><span class="line"> docker-init:</span><br><span class="line">  Version:          0.18.0</span><br><span class="line">  GitCommit:        fec3683</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker info  <span class="comment"># docker容器信息</span></span></span><br><span class="line">Client:</span><br><span class="line"> Debug Mode: false</span><br><span class="line"></span><br><span class="line">Server:</span><br><span class="line"> Containers: 0  # 容器</span><br><span class="line">  Running: 0    # 运行的容器个数</span><br><span class="line">  Paused: 0     # 暂停的容器个数</span><br><span class="line">  Stopped: 0    # 停止的容器个数</span><br><span class="line"> Images: 0      # docker镜像个数</span><br><span class="line"> Server Version: 19.03.12   # docker服务端版本</span><br><span class="line"> Storage Driver: overlay2   # 存储</span><br><span class="line">  Backing Filesystem: xfs   # 文件系统</span><br><span class="line">  Supports d_type: true</span><br><span class="line">  Native Overlay Diff: true</span><br><span class="line"> Logging Driver: json-file</span><br><span class="line"> Cgroup Driver: cgroupfs</span><br><span class="line"> Plugins:          # 插件</span><br><span class="line">  Volume: local</span><br><span class="line">  Network: bridge host ipvlan macvlan null overlay</span><br><span class="line">  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog</span><br><span class="line"> Swarm: inactive</span><br><span class="line"> Runtimes: runc</span><br><span class="line"> Default Runtime: runc</span><br><span class="line"> Init Binary: docker-init</span><br><span class="line"> containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429</span><br><span class="line"> runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd</span><br><span class="line"> init version: fec3683</span><br><span class="line"> Security Options:    # 安全选项</span><br><span class="line">  seccomp</span><br><span class="line">   Profile: default</span><br><span class="line"> Kernel Version: 3.10.0-957.el7.x86_64   # 本地服务器内核版本</span><br><span class="line"> Operating System: CentOS Linux 7 (Core)  # 本地服务器操作系统</span><br><span class="line"> OSType: linux       # 操作系统类型</span><br><span class="line"> Architecture: x86_64    # 本地服务器架构</span><br><span class="line"> CPUs: 4     # cpu个数</span><br><span class="line"> Total Memory: 7.62GiB   # 本地服务器内存大小</span><br><span class="line"> Name: docker     # 本地服务器主机名</span><br><span class="line"> ID: CTSU:SHD4:IUXR:4NUI:BC2G:D2JO:OVS2:2VNN:3OP5:GOV5:EUO7:NI2A</span><br><span class="line"> Docker Root Dir: /var/lib/docker   # docker根目录</span><br><span class="line"> Debug Mode: false</span><br><span class="line"> Registry: https://index.docker.io/v1/   # 默认docker仓库地址</span><br><span class="line"> Labels:</span><br><span class="line"> Experimental: false</span><br><span class="line"> Insecure Registries:</span><br><span class="line">  127.0.0.0/8</span><br><span class="line"> Registry Mirrors:     # 加速镜像地址</span><br><span class="line">  https://registry.docker-cn.com/    # 在/etc/docker/daemon.json定义</span><br><span class="line">  http://hub-mirror.c.163.com/</span><br><span class="line"> Live Restore Enabled: false</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker根目录下的文件夹</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">ll  /var/lib/docker</span>    </span><br><span class="line">total 4</span><br><span class="line">drwx--x--x  4 root root  120 Feb 15 10:49 buildkit</span><br><span class="line">drwx-----x  5 root root  222 Mar 31 19:51 containers   </span><br><span class="line">drwx------  3 root root   22 Feb 15 10:49 image        </span><br><span class="line">drwxr-x---  3 root root   19 Feb 15 10:49 network     </span><br><span class="line">drwx-----x 19 root root 4096 Mar 31 19:51 overlay2</span><br><span class="line">drwx------  4 root root   32 Feb 15 10:49 plugins</span><br><span class="line">drwx------  2 root root    6 Mar 31 19:46 runtimes</span><br><span class="line">drwx------  2 root root    6 Feb 15 10:49 swarm</span><br><span class="line">drwx------  2 root root    6 Mar 31 19:46 tmp</span><br><span class="line">drwx------  2 root root    6 Feb 15 10:49 trust</span><br><span class="line">drwx-----x  2 root root   50 Mar 31 19:46 volumes</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装完成后系统上将会多出一个docker0的网络，该网卡随着容器的运行而运行，如果没有容器运行该网卡状态为down</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">ifconfig  docker0</span>  </span><br><span class="line">docker0: flags=4099&lt;UP,BROADCAST,MULTICAST&gt;  mtu 1500</span><br><span class="line">        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255</span><br><span class="line">        inet6 fe80::42:c0ff:febc:f72a  prefixlen 64  scopeid 0x20&lt;link&gt;</span><br><span class="line">        ether 02:42:c0:bc:f7:2a  txqueuelen 0  (Ethernet)</span><br><span class="line">        RX packets 0  bytes 0 (0.0 B)</span><br><span class="line">        RX errors 0  dropped 0  overruns 0  frame 0</span><br><span class="line">        TX packets 2  bytes 180 (180.0 B)</span><br><span class="line">        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">运行容器后，会多出容器的IP信息，网络将后后面的章节详细讲解，这里不赘述</span></span><br></pre></td></tr></table></figure>

<p> Docker程序环境：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">默认安装的文件如下</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">rpm -ql docker-ce</span> </span><br><span class="line">/usr/bin/docker-init</span><br><span class="line">/usr/bin/docker-proxy</span><br><span class="line">/usr/bin/dockerd</span><br><span class="line">/usr/lib/systemd/system/docker.service</span><br><span class="line">/usr/lib/systemd/system/docker.socket</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker的配置文件可手动新建</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># docker网络文件--/etc/sysconfig/docker-network</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># docker存储文件--/etc/sysconfig/docker-storage</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># docker主配置文件--/etc/sysconfig/docker</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># Docker registry配置文件--/etc/conftainers/registries.conf</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># Docker镜像加速文件--/etc/docker/daemon.json</span></span></span><br></pre></td></tr></table></figure>

<h2 id="yum离线安装"><a href="#yum离线安装" class="headerlink" title="yum离线安装"></a>yum离线安装</h2><p>yum离线安装的实质是在外网下载并制作docker的本地仓库，然后上传至内网进行安装。</p>
<h3 id="安装Yumdownloader工具"><a href="#安装Yumdownloader工具" class="headerlink" title="安装Yumdownloader工具"></a>安装<code>Yumdownloader</code>工具</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">rpm -qi yum-utils</span></span><br><span class="line">package yum-utils is not installed</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum -y install yum-utils</span></span><br></pre></td></tr></table></figure>

<h3 id="配置yum源-1"><a href="#配置yum源-1" class="headerlink" title="配置yum源"></a>配置yum源</h3><p>阿里云源地址：<a target="_blank" rel="noopener" href="https://mirrors.aliyun.com/docker-ce/linux/centos/">https://mirrors.aliyun.com/docker-ce/linux/centos/</a></p>
<p>配置方法：<a target="_blank" rel="noopener" href="https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.4fe81b11t6PFN9">https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.4fe81b11t6PFN9</a></p>
<p>下载下图中的<code>docker-ce.repo</code>文件，上传至服务器。</p>
<p><img src="/pic/docker-pic/image-20221022122214474.png" alt="image-20221022122214474"></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /etc/yum.repos.d/docker-ce.repo</span></span><br><span class="line">/etc/yum.repos.d/docker-ce.repo</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum clean all &amp;&amp; yum repolist</span></span><br><span class="line">···</span><br><span class="line">repo id                         repo name                    status</span><br><span class="line">base/7/x86_64                   CentOS-7 - Base              10,072</span><br><span class="line">docker-ce-stable/7/x86_64       Docker CE Stable - x86_64    169</span><br><span class="line">extras/7/x86_64                 CentOS-7 - Extras            515</span><br><span class="line">updates/7/x86_64                CentOS-7 - Updates           4,300</span><br><span class="line">repolist: 15,056</span><br></pre></td></tr></table></figure>

<h3 id="下载docker及其依赖环境"><a href="#下载docker及其依赖环境" class="headerlink" title="下载docker及其依赖环境"></a>下载docker及其依赖环境</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">mkdir</span> /root/mydocker</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yumdownloader --resolve --destdir /root/mydocker/  \</span></span><br><span class="line"><span class="language-bash">      yum-utils device-mapper-persistent-data lvm2 docker-ce createrepo</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> mydocker/</span></span><br><span class="line">audit-2.8.5-4.el7.x86_64.rpm                              docker-scan-plugin-0.17.0-3.el7.x86_64.rpm</span><br><span class="line">audit-libs-2.8.5-4.el7.x86_64.rpm                         fuse3-libs-3.6.1-4.el7.x86_64.rpm</span><br><span class="line">audit-libs-python-2.8.5-4.el7.x86_64.rpm                  fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm</span><br><span class="line">checkpolicy-2.5-8.el7.x86_64.rpm                          libcgroup-0.41-21.el7.x86_64.rpm</span><br><span class="line">containerd.io-1.6.8-3.1.el7.x86_64.rpm                    libseccomp-2.3.1-4.el7.x86_64.rpm</span><br><span class="line">container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm      libsemanage-python-2.5-14.el7.x86_64.rpm</span><br><span class="line">createrepo-0.9.9-28.el7.noarch.rpm                        lvm2-2.02.187-6.el7_9.5.x86_64.rpm</span><br><span class="line">deltarpm-3.6-3.el7.x86_64.rpm                             lvm2-libs-2.02.187-6.el7_9.5.x86_64.rpm</span><br><span class="line">device-mapper-1.02.170-6.el7_9.5.x86_64.rpm               policycoreutils-2.5-34.el7.x86_64.rpm</span><br><span class="line">device-mapper-event-1.02.170-6.el7_9.5.x86_64.rpm         policycoreutils-python-2.5-34.el7.x86_64.rpm</span><br><span class="line">device-mapper-event-libs-1.02.170-6.el7_9.5.x86_64.rpm    python-deltarpm-3.6-3.el7.x86_64.rpm</span><br><span class="line">device-mapper-libs-1.02.170-6.el7_9.5.x86_64.rpm          python-IPy-0.75-6.el7.noarch.rpm</span><br><span class="line">device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64.rpm  setools-libs-3.3.8-4.el7.x86_64.rpm</span><br><span class="line">docker-ce-20.10.18-3.el7.x86_64.rpm                       slirp4netns-0.4.3-4.el7_8.x86_64.rpm</span><br><span class="line">docker-ce-cli-20.10.18-3.el7.x86_64.rpm                   yum-utils-1.1.31-54.el7_8.noarch.rpm</span><br><span class="line">docker-ce-rootless-extras-20.10.18-3.el7.x86_64.rpm</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> mydocker/ | <span class="built_in">wc</span> -l</span></span><br><span class="line">31</span><br></pre></td></tr></table></figure>

<h3 id="制作yum仓库"><a href="#制作yum仓库" class="headerlink" title="制作yum仓库"></a>制作yum仓库</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cd</span> /root/mydocker/</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm</span></span><br><span class="line">Preparing...                          ################################# [100%]</span><br><span class="line">Updating / installing...</span><br><span class="line">   1:deltarpm-3.6-3.el7               ################################# [100%]</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm</span></span><br><span class="line">Preparing...                          ################################# [100%]</span><br><span class="line">Updating / installing...</span><br><span class="line">   1:python-deltarpm-3.6-3.el7        ################################# [100%]</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm</span></span><br><span class="line">Preparing...                          ################################# [100%]</span><br><span class="line">Updating / installing...</span><br><span class="line">   1:createrepo-0.9.9-28.el7          ################################# [100%]</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">createrepo  /root/mydocker/</span></span><br><span class="line">Spawning worker 0 with 16 pkgs</span><br><span class="line">Spawning worker 1 with 15 pkgs</span><br><span class="line">Workers Finished</span><br><span class="line">Saving Primary metadata</span><br><span class="line">Saving file lists metadata</span><br><span class="line">Saving other metadata</span><br><span class="line">Generating sqlite DBs</span><br><span class="line">Sqlite DBs complete</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /root/mydocker/ | <span class="built_in">wc</span> -l</span></span><br><span class="line">32</span><br></pre></td></tr></table></figure>

<h3 id="内网安装"><a href="#内网安装" class="headerlink" title="内网安装"></a>内网安装</h3><p>将上一个章节得到的软件包上传至内网，并配置yum源，即可安装docker-ce</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># mkdir /etc/yum.repos.d/bak</span></span><br><span class="line"><span class="comment"># mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak</span></span><br><span class="line"><span class="comment"># vim /etc/yum.repos.d/docker.repo</span></span><br><span class="line">[docker]</span><br><span class="line">name=docker</span><br><span class="line">baseurl=file:///root/mydocker</span><br><span class="line">gpgcheck=<span class="number">0</span></span><br><span class="line">enabled=<span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># yum clean all &amp;&amp; yum repolist</span></span><br><span class="line">···</span><br><span class="line">repo <span class="built_in">id</span>                    repo name               status</span><br><span class="line">docker                     docker                  <span class="number">31</span></span><br><span class="line">repolist: <span class="number">31</span></span><br><span class="line"><span class="comment"># yum -y install docker-ce</span></span><br><span class="line"></span><br><span class="line"><span class="comment">## 安装完成后，可检查docker版本</span></span><br><span class="line"><span class="comment"># docker --version</span></span><br><span class="line">Docker version <span class="number">20.10</span><span class="number">.18</span>, build b40c2f6</span><br></pre></td></tr></table></figure>

<h2 id="二进制安装docker"><a href="#二进制安装docker" class="headerlink" title="二进制安装docker"></a>二进制安装docker</h2><h3 id="下载docker二进制文件"><a href="#下载docker二进制文件" class="headerlink" title="下载docker二进制文件"></a>下载docker二进制文件</h3><p>下载地址：<a target="_blank" rel="noopener" href="https://download.docker.com/linux/static/stable/x86_64/">https://download.docker.com/linux/static/stable/x86_64/</a></p>
<p><img src="/pic/docker-pic/image-20220707142321648.png" alt="image-20220707142321648"></p>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><h4 id="上传二进制包到服务器"><a href="#上传二进制包到服务器" class="headerlink" title="上传二进制包到服务器"></a>上传二进制包到服务器</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> docker-20.10.9.tgz</span></span><br><span class="line">docker-20.10.9.tgz</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">tar xzf docker-20.10.9.tgz</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> docker</span></span><br><span class="line">docker             docker-containerd-ctr   dockerd      docker-proxy</span><br><span class="line">docker-containerd  docker-containerd-shim  docker-init  docker-runc</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">mv</span> docker/* /usr/bin/</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker --version  <span class="comment"># 查看docker版本</span></span></span><br><span class="line">Docker version 20.10.9, build c2ea9bc</span><br></pre></td></tr></table></figure>

<h4 id="编写docker-service，设置systemd启动"><a href="#编写docker-service，设置systemd启动" class="headerlink" title="编写docker.service，设置systemd启动"></a>编写docker.service，设置systemd启动</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim /etc/systemd/system/docker.service</span></span><br><span class="line">[Unit]</span><br><span class="line">Description=Docker Application Container Engine</span><br><span class="line">Documentation=https://docs.docker.com</span><br><span class="line">After=network-online.target firewalld.service</span><br><span class="line">Wants=network-online.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=notify</span><br><span class="line">ExecStart=/usr/bin/dockerd --debug=true --live-restore=true</span><br><span class="line">ExecReload=/bin/kill -s HUP $MAINPID</span><br><span class="line">LimitNOFILE=infinity</span><br><span class="line">LimitNPROC=infinity</span><br><span class="line">LimitCORE=infinity</span><br><span class="line">TimeoutStartSec=0</span><br><span class="line">Delegate=yes</span><br><span class="line">KillMode=process</span><br><span class="line">Restart=on-failure</span><br><span class="line">StartLimitBurst=3</span><br><span class="line">StartLimitInterval=60s</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># --debug=true：表示开启服务端debug功能</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># --live-restore=true：表示在重启docker服务的时候不重启容器，默认重启docker会停止重启（除非设置--restart=always）</span></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">chmod</span> +x /etc/systemd/system/docker.service</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl daemon-reload</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl <span class="built_in">enable</span> docker</span></span><br></pre></td></tr></table></figure>

<h4 id="设置网桥转发"><a href="#设置网桥转发" class="headerlink" title="设置网桥转发"></a>设置网桥转发</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim /etc/sysctl.conf  <span class="comment"># 在文件中追加下面三行内容</span></span></span><br><span class="line">net.bridge.bridge-nf-call-ip6tables = 1</span><br><span class="line">net.bridge.bridge-nf-call-iptables = 1</span><br><span class="line">net.bridge.bridge-nf-call-arptables = 1</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">sysctl -p</span></span><br><span class="line">net.bridge.bridge-nf-call-ip6tables = 1</span><br><span class="line">net.bridge.bridge-nf-call-iptables = 1</span><br><span class="line">net.bridge.bridge-nf-call-arptables = 1</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：bridge-nf使得netfilter（iptables底层实现）可以对Linux网桥上的IPv4&#x2F;ARP&#x2F;IPv6包过滤。比如，设置net.bridge.bridge-nf-call-iptables＝1后，二层的网桥在转发包时也会被iptables的FORWARD规则所过滤。</p>
</blockquote>
<h4 id="启动docker服务"><a href="#启动docker服务" class="headerlink" title="启动docker服务"></a>启动docker服务</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl start docker</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker info</span></span><br><span class="line">Client:               # 下面是client客户端的信息</span><br><span class="line"> Context:    default</span><br><span class="line"> Debug Mode: false   # client端是否开启调试模式</span><br><span class="line"></span><br><span class="line">Server:               # 下面是server服务端的信息</span><br><span class="line"> Containers: 0        # 目前服务器上存在的的容器个数</span><br><span class="line">  Running: 0          # 在运行的容器个数</span><br><span class="line">  Paused: 0           # 暂停的容器个数</span><br><span class="line">  Stopped: 0          # 停止的容器个数</span><br><span class="line"> Images: 0            # 镜像个数</span><br><span class="line"> Server Version: 20.10.9   # docker服务端版本</span><br><span class="line"> Storage Driver: overlay2  # 正在使用的存储引擎</span><br><span class="line">  Backing Filesystem: xfs  # 后端文件系统类型</span><br><span class="line">  Supports d_type: true    # 是否支持 d_type</span><br><span class="line">  Native Overlay Diff: true  # 是否支持差异数据存储</span><br><span class="line">  userxattr: false         # </span><br><span class="line"> Logging Driver: json-file   # 日志类型 </span><br><span class="line"> Cgroup Driver: cgroupfs     # cgroup类型</span><br><span class="line"> Cgroup Version: 1         # cgroup版本</span><br><span class="line"> Plugins:              # 插件</span><br><span class="line">  Volume: local        # 卷</span><br><span class="line">  Network: bridge host ipvlan macvlan null overlay  # 网络类型</span><br><span class="line">  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog  # 日志类型</span><br><span class="line"> Swarm: inactive   # 是否支持swarm</span><br><span class="line"> Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc  # 已安装的容器运行时</span><br><span class="line"> Default Runtime: runc      # 默认容器运行时</span><br><span class="line"> Init Binary: docker-init   # 初始化容器的守护进程，即 pid 为 1的进程</span><br><span class="line"> containerd version: 5b46e404f6b9f661a205e28d59c982d3634148f8  # 容器版本</span><br><span class="line"> runc version: v1.0.2-0-g52b36a2d   # 运行时版本</span><br><span class="line"> init version: de40ad0   # init 版本</span><br><span class="line"> Security Options:       # 安全选项</span><br><span class="line">  seccomp                # 安全计算模块，即制容器操作，https://docs.docker.com/engine/security/seccomp/</span><br><span class="line">   Profile: default      # 配置文件</span><br><span class="line"> Kernel Version: 3.10.0-957.el7.x86_64      # 宿主机内核版本</span><br><span class="line"> Operating System: CentOS Linux 7 (Core)    # 宿主机操作系统</span><br><span class="line"> OSType: linux          # 宿主机操作系统类型</span><br><span class="line"> Architecture: x86_64   # 宿主机架构</span><br><span class="line"> CPUs: 2                # 宿主机cpu个数</span><br><span class="line"> Total Memory: 3.683GiB   # 宿主机内存总量</span><br><span class="line"> Name: VM-base           # 宿主机主机名</span><br><span class="line"> ID: CVMH:67RG:K37Q:FYLP:VF2I:72DS:US7V:DMNG:SNSE:4O5U:JQUL:Q737   # 宿主机ID</span><br><span class="line"> Docker Root Dir: /var/lib/docker   # 宿主机上docker数据的保存目录</span><br><span class="line"> Debug Mode: true     # 是否开启debug模式</span><br><span class="line">  File Descriptors: 25   </span><br><span class="line">  Goroutines: 40</span><br><span class="line">  System Time: 2022-07-07T14:15:05.663292589+08:00  # 系统时间</span><br><span class="line">  EventsListeners: 0</span><br><span class="line"> Registry: https://index.docker.io/v1/  # 仓库</span><br><span class="line"> Labels:    # 标签</span><br><span class="line"> Experimental: false   # 是否测试版</span><br><span class="line"> Insecure Registries:  # 非安全的仓库路径</span><br><span class="line">  127.0.0.0/8</span><br><span class="line"> Live Restore Enabled: true   # 是否开启活动重启 (重启dockerdocker-daemon 不关闭容器 )</span><br><span class="line"> Product License: Community Engine  # 产品license信息，社区版</span><br></pre></td></tr></table></figure>

<h3 id="容器状态与docker服务状态的关系"><a href="#容器状态与docker服务状态的关系" class="headerlink" title="容器状态与docker服务状态的关系"></a>容器状态与docker服务状态的关系</h3><p>默认情况下，容器会随docker服务的重启和停止而停止运行。但我们可以通过下面两种方式设置保持容器永久运行：</p>
<ul>
<li>方法一：设置docker启动项为&#96;&#96;–live-restore&#x3D;true&#96;；</li>
<li>方法二：启动容器时添加&#96;&#96;–restart&#x3D;always&#96;参数，只要容器停止就立马重启；</li>
</ul>
<blockquote>
<p>此处重启docker不影响容器的原因是我们设置了docker启动项–live-restore&#x3D;true的原因</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker run -it  -d busybox</span></span><br><span class="line">Unable to find image &#x27;busybox:latest&#x27; locally</span><br><span class="line">latest: Pulling from library/busybox</span><br><span class="line">19d511225f94: Pull complete</span><br><span class="line">Digest: sha256:3614ca5eacf0a3a1bcc361c939202a974b4902b9334ff36eb29ffe9011aaad83</span><br><span class="line">Status: Downloaded newer image for busybox:latest</span><br><span class="line">470dcf7dff5d9e0898e 38764183c413c693718d66f61db6e82398dc7f5fbc063</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker ps</span></span><br><span class="line">CONTAINER ID   IMAGE     COMMAND   CREATED             STATUS             PORTS     NAMES</span><br><span class="line">470dcf7dff5d   busybox   &quot;sh&quot;      About an hour ago   Up About an hour             funny_visvesvaraya</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl restart docker  <span class="comment"># 重启docker服务，查看容器启动时间是否有变化</span></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker ps</span></span><br><span class="line">CONTAINER ID   IMAGE     COMMAND   CREATED             STATUS             PORTS     NAMES</span><br><span class="line">470dcf7dff5d   busybox   &quot;sh&quot;      About an hour ago   Up About an hour             funny_visvesvaraya</span><br></pre></td></tr></table></figure>

<p>启动docker时设置<code>Live Restore</code>参数为<code>false</code>，再次重启docker查看容器是否重启</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim /etc/systemd/system/docker.service</span></span><br><span class="line">[Unit]</span><br><span class="line">Description=Docker Application Container Engine</span><br><span class="line">Documentation=https://docs.docker.com</span><br><span class="line">After=network-online.target firewalld.service</span><br><span class="line">Wants=network-online.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=notify</span><br><span class="line">ExecStart=/usr/bin/dockerd --debug=true --live-restore=false   # --live-restore的值为false</span><br><span class="line">ExecReload=/bin/kill -s HUP $MAINPID</span><br><span class="line">LimitNOFILE=infinity</span><br><span class="line">LimitNPROC=infinity</span><br><span class="line">LimitCORE=infinity</span><br><span class="line">TimeoutStartSec=0</span><br><span class="line">Delegate=yes</span><br><span class="line">KillMode=process</span><br><span class="line">Restart=on-failure</span><br><span class="line">StartLimitBurst=3</span><br><span class="line">StartLimitInterval=60s</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl daemon-reload</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker ps</span></span><br><span class="line">CONTAINER ID   IMAGE     COMMAND   CREATED             STATUS             PORTS     NAMES</span><br><span class="line">470dcf7dff5d   busybox   &quot;sh&quot;      About an hour ago   Up About an hour             funny_visvesvaraya</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl restart docker  <span class="comment"># 重启docker服务，并查看容器运行状态</span></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker ps -a   <span class="comment"># 重启docker后，容器已经退出，未自动重启</span></span></span><br><span class="line">CONTAINER ID   IMAGE     COMMAND   CREATED             STATUS                        PORTS     NAMES</span><br><span class="line">470dcf7dff5d   busybox   &quot;sh&quot;      About an hour ago   Exited (137) 15 seconds ago             funny_visvesvaraya</span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://rushiy.gitee.io">rushiy</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://rushiy.gitee.io/docker/%E5%AE%89%E8%A3%85docker/">https://rushiy.gitee.io/docker/%E5%AE%89%E8%A3%85docker/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://rushiy.gitee.io" target="_blank">如是的学习博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/docker/">docker</a></div><div class="post_share"><div class="social-share" data-image="" data-sites="wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/favicon.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">rushiy</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">3</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="mailto:rushiy@reg.email.cn" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#yum%E5%9C%A8%E7%BA%BF%E5%AE%89%E8%A3%85%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">yum在线安装：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AEyum%E6%BA%90"><span class="toc-number">1.1.</span> <span class="toc-text">配置yum源</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%89%E8%A3%85docker"><span class="toc-number">1.2.</span> <span class="toc-text">安装docker</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F"><span class="toc-number">1.3.</span> <span class="toc-text">配置镜像加速</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#yum%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85"><span class="toc-number">2.</span> <span class="toc-text">yum离线安装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%89%E8%A3%85Yumdownloader%E5%B7%A5%E5%85%B7"><span class="toc-number">2.1.</span> <span class="toc-text">安装Yumdownloader工具</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AEyum%E6%BA%90-1"><span class="toc-number">2.2.</span> <span class="toc-text">配置yum源</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BDdocker%E5%8F%8A%E5%85%B6%E4%BE%9D%E8%B5%96%E7%8E%AF%E5%A2%83"><span class="toc-number">2.3.</span> <span class="toc-text">下载docker及其依赖环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%B6%E4%BD%9Cyum%E4%BB%93%E5%BA%93"><span class="toc-number">2.4.</span> <span class="toc-text">制作yum仓库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E7%BD%91%E5%AE%89%E8%A3%85"><span class="toc-number">2.5.</span> <span class="toc-text">内网安装</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%AE%89%E8%A3%85docker"><span class="toc-number">3.</span> <span class="toc-text">二进制安装docker</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BDdocker%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%96%87%E4%BB%B6"><span class="toc-number">3.1.</span> <span class="toc-text">下载docker二进制文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%89%E8%A3%85"><span class="toc-number">3.2.</span> <span class="toc-text">安装</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%8A%E4%BC%A0%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%8C%85%E5%88%B0%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="toc-number">3.2.1.</span> <span class="toc-text">上传二进制包到服务器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BC%96%E5%86%99docker-service%EF%BC%8C%E8%AE%BE%E7%BD%AEsystemd%E5%90%AF%E5%8A%A8"><span class="toc-number">3.2.2.</span> <span class="toc-text">编写docker.service，设置systemd启动</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E7%BD%91%E6%A1%A5%E8%BD%AC%E5%8F%91"><span class="toc-number">3.2.3.</span> <span class="toc-text">设置网桥转发</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8docker%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.2.4.</span> <span class="toc-text">启动docker服务</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%B9%E5%99%A8%E7%8A%B6%E6%80%81%E4%B8%8Edocker%E6%9C%8D%E5%8A%A1%E7%8A%B6%E6%80%81%E7%9A%84%E5%85%B3%E7%B3%BB"><span class="toc-number">3.3.</span> <span class="toc-text">容器状态与docker服务状态的关系</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/django/Django%E6%A8%A1%E6%9D%BF%E7%B3%BB%E7%BB%9F/" title="Django模板系统"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Django模板系统"/></a><div class="content"><a class="title" href="/django/Django%E6%A8%A1%E6%9D%BF%E7%B3%BB%E7%BB%9F/" title="Django模板系统">Django模板系统</a><time datetime="2022-11-04T07:08:03.000Z" title="发表于 2022-11-04 15:08:03">2022-11-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/django/Django%E8%A7%86%E5%9B%BE/" title="Django视图"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Django视图"/></a><div class="content"><a class="title" href="/django/Django%E8%A7%86%E5%9B%BE/" title="Django视图">Django视图</a><time datetime="2022-11-03T07:07:51.000Z" title="发表于 2022-11-03 15:07:51">2022-11-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/django/Django%E8%B7%AF%E7%94%B1%E7%B3%BB%E7%BB%9F/" title="Django路由系统"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Django路由系统"/></a><div class="content"><a class="title" href="/django/Django%E8%B7%AF%E7%94%B1%E7%B3%BB%E7%BB%9F/" title="Django路由系统">Django路由系统</a><time datetime="2022-11-02T07:07:34.000Z" title="发表于 2022-11-02 15:07:34">2022-11-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/django/%E8%B5%B0%E8%BF%9BDjango/" title="走进Django"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="走进Django"/></a><div class="content"><a class="title" href="/django/%E8%B5%B0%E8%BF%9BDjango/" title="走进Django">走进Django</a><time datetime="2022-11-01T07:01:20.000Z" title="发表于 2022-11-01 15:01:20">2022-11-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/python/python%E5%B8%B8%E7%94%A8%E6%A8%A1%E5%9D%97/" title="python常用模块"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python常用模块"/></a><div class="content"><a class="title" href="/python/python%E5%B8%B8%E7%94%A8%E6%A8%A1%E5%9D%97/" title="python常用模块">python常用模块</a><time datetime="2022-10-28T15:34:07.000Z" title="发表于 2022-10-28 23:34:07">2022-10-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2022 By rushiy</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>